<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>餐店管理 后台列表</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="stylesheet" href="../../Res/LayUI/css/layui.css" media="all">
<script src="../../js/jquery-1.10.2.js" charset="utf-8"></script>
<script src="../../Res/JS/date.js"></script>
<script type="text/html" id="optime">  
  	{{dateFormat(d.optime)}}
</script>

<script type="text/html" id="mealLogo">
	<img src="../../{{(d.mealLogo)}}">	
</script>
<link rel="stylesheet" href="../../Res/LayUI/css/modules/treeselect.css">
<!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>
	<table class="layui-hide" id="Meal" lay-filter="demo"></table>
<script type="text/html" id="vet">
	{{# if(d.isva=='1'){ }}
		<a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="vet">审核</a>
	{{# } else if(d.isva=='2'){}}
		<a class="layui-btn layui-btn-xs layui-btn-disabled">已审核</a>
	{{# } }}
</script>
 
<script src="../../Res/LayUI/layui.js"></script>
<script>

layui.use(['laydate', 'laypage', 'layer', 'table', 'upload', 'element'], function(){
	  var laydate = layui.laydate //日期
	  ,laypage = layui.laypage //分页
	  layer = layui.layer //弹层
	  ,table = layui.table //表格
	  ,upload = layui.upload //上传
	  ,element = layui.element; //元素操作
	 
	  
	  //监听Tab切换
	  element.on('tab(demo)', function(data){
	    layer.msg('切换了：'+ this.innerHTML);
	    console.log(data);
	  });
	  
	  //执行一个 table 实例
	  table.render({
	     elem: '#Meal'//绑定table表格
	    ,width:1500 //表格宽度
	    ,height: 500 //表格高度
	    ,url: '../../meal/select' //数据接口
	    ,page: true //开启分页
	    ,limit: 10
	    ,method:'post'
	    ,cols: [[ //表头
	       {type:'checkbox', fixed: 'left'}
	      ,{field: 'mealId', title: '餐店ID', width:130, fixed: 'left'}
	      ,{field: 'mealName', title: '餐店名称', width:140}
	      ,{field: 'mealSite', title: '餐店地址', width:140}
	      ,{field: 'mealPerson', title: '联系人', width:140}
	      ,{field: 'mealPhone', title: '联系电话', width: 140}
	      ,{field: 'mealLogo', title: '店铺Logo', width: 140, templet:'#mealLogo'}
	      ,{field: 'oper', title: '操作人', width: 140}
	      ,{field: 'optime', title: '操作时间',templet: '#optime', width: 180}
	      ,{field: 'isva', title: '审核', width: 120, align:'center', toolbar: '#vet'}
	    ]]
	  	,id: 'testReload'
	  });
	  
	//监听工具条
	  table.on('tool(demo)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
	    var data = obj.data //获得当前行数据
	    ,layEvent = obj.event; //获得 lay-event 对应的值
	    if(layEvent === 'del'){
	      var mealId=data.mealId;
	      layer.confirm('确认删除？', function(index){
	        layer.close(index);
	        //使用jquery的ajax方式向后台提交数据
			var url = "../../meal/del";
			var data={mealId:mealId};
				$.post(url,data,function(data){
					if(data=="ok"){
						layer.msg('删除成功', {
							  icon: 1,
							  time: 1000 //1秒关闭（如果不配置，默认是3秒）
							}, function(index, item){
							//	alert(12);
								location.reload(); // 页面刷新
						});
					}
					
				});
	      	});
	    } else if(layEvent === 'edit'){
	    	var mealId=data.mealId;

	    	var goodsTypeName=data.goodsTypeName;
	        //使用jquery的ajax方式向后台提交数据
			var url = "../../meal/findById";
			var data={mealId:mealId};
			$.post(url,data,function(data){
				 layer.open({
					  type: 2,
					  area : ['60%' , '90%'],//弹出框大小
					  shift:1,//弹出框动画效果
					  content: ['mealupdate.html','on'], //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
				 	  success:function(layero,index){
				 		  var body = layer.getChildFrame('body',index);//确定两个页面之间的父子关系
				 		  var iframeWin = window[layero.find('iframe')[0]['name']];//子页面对象
				 		  console.log(body.html()) //得到iframe页的body内容
				 		 body.find("#mealId").val(data.mealId);
				 		  body.find("#mealName").val(data.mealName);
				 		  body.find("#mealSite").val(data.mealSite);
				 		  body.find("#mealPerson").val(data.mealPerson);
				 		  body.find("#mealPhone").val(data.mealPhone);
				 		  body.find("#mealLogo").val(data.mealLogo);
				 		  body.find("#isva").val(data.isva);
				 		  body.find("#oper").val(data.oper);
				 	  }			 
					}); 	
				/* 
			 eval("var ehyManagerVo="+data); */
				   
			},dataType="JSON");
	    }else if (obj.event === 'vet') {
			$.ajax({
				asyn : true,
				type : "POST",
				url : "../../meal/updateVet",
				data:{"mealId":data.mealId},
				success : function(msg) {
					table.reload('testReload');
				},
				error : function(fh) {
				}
			});
			
		}
	  });
	  
	  //条件查询
	  var $ = layui.$;
	  $('.demoTable .layui-btn').on('click', function(){
		 var demoReload = $('#demoReload');
		 //执行重载
	     table.reload('testReload', {
	       page: {
	         curr: 1 //重新从第 1 页开始
	       }
	       ,where: {
	    	   mealName: demoReload.val()
	       }
	     });
	  });
	});
	   
</script>
</body>
</html>